<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>   
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";            
%>

<!DOCTYPE html>  
<html>
  <head>
    <base href="<%=basePath%>">   
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<link rel="stylesheet" type="text/css" href="css/edittable.css">
	<link rel="stylesheet" type="text/css" href="css/validate.css">
	<script type="text/javascript" src="js/jquery-1.8.0.js"></script>
	
	<script>
		function showInfo(item,msg){
			$("#"+item.id+"_msg").html(msg);
			$("#"+item.id+"_msg").removeClass().addClass("validate_info");
		}
		function showError(item,msg){
			$("#"+item.id+"_msg").html(msg);
			$("#"+item.id+"_msg").removeClass().addClass("validate_error");
		}
		function showOk(item){
			$("#"+item.id+"_msg").html("√");
			$("#"+item.id+"_msg").removeClass().addClass("validate_ok");
		}
		//验证用户名
		function check_userName(item){
			var result=true;
			var reg=/^\w{4,12}$/;
			if(!reg.test(item.value)){
				result=false;
				showError(item,"用户名格式不合法! ");
			}else{
				showOk(item);
			}
			return result;
		}
		//验证密码
		function check_password(item){
			var result=true;
			var reg=/^\w{6,20}$/
			if(!reg.test(item.value)){
				result=false;
				showError(item,"密码格式不合法")
			}else{
				showOk(item);
			}
			return result;
		}
		//验证两次密码输入是否相同
		function check_pwdconfirm(item){
			var result=true;
			if(item.value==""){
				result=false;
				showError(item,"请重复输入密码")
			}else if(item.value!=$("#password").val()){
				result=false;
				showError(item,"两次输入密码不一致")
			}else{
				showOk(item);
			}
			return result;
		}
		
		function yanzheng(){
			var result=true;
			if(check_userName($("#adminName")[0])==false){
				result=false;
				
			}
			if(check_password($("#password")[0])==false){
				result=false;
			}
			if(check_pwdconfirm($("#pwdconfirm")[0])==false){
				result=false;
			}
			if(result==true){
				return confirm("确定添加吗");
			}else{
				alert("请正确输入信息");
			}
			return result;
		}
		
	</script>
  </head>
  
  <body>
    <form action="AdminServlet.do"  method="post"> 
	 	 <input type="hidden" name ="flag" value="addAdmin" >
		 <table class="edit_table" >
		 		<tr>
		 			 	<td class="td_info">用户账号:</td>	
		 			 	<td class="td_input_short"> 
		 			 		<input type="text" class="txtbox" id="adminName" name="adminName" 
		 			 		onfocus="showInfo(this,'4-12位的字母或数字')" onblur="check_userName(this)" value="${admin.adminName }" /> 
		 			 	</td>   
		 			 	<td>
		 			 		<label id="adminName_msg"></label>
		 			 	</td> 
		 		</tr>
		 			<tr>
		 				<td class="td_info">用户密码:</td>	
		 				<td>
		 					<input type="password"  class="txtbox"  name="password"  id="password" name="adminName" 
		 					       onfocus="showInfo(this,'数字或英文,6-20位')" onblur="check_password(this)" value="${admin.password }"/>
		 				</td> 
		 				<td><label id="password_msg" ></label></td>	
		 		</tr>
		 			<tr>
		 				<td class="td_info">重复密码:</td>	
		 				<td><input type="password" class="txtbox" id="pwdconfirm"  
		 				           onfocus="showInfo(this,'请重复输入密码')" onblur="check_pwdconfirm(this)" value="${admin.password }"/> 
		 				</td>
		 				<td><label  class="validate_info"  id="pwdconfirm_msg"></label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info">备注信息:</td>	
		 			<td><textarea rows="4" cols="27" name="note" class="txtarea"></textarea> </td>	
		 			<td><label></label></td>	
		 		</tr>
		 		<tr>
		 			<td class="td_info"> </td>	
		 			<td> 
		 			<input class="form_btn" type="submit" value="提交" onclick="return yanzheng()"/> 
		 			<input type="reset"  class="form_btn" value="重置" />	
		 			<label id="result_msg" class="result_msg">${msg }</label>
		 			
		 				
		 			</td>	
		 		</tr>
		</table>
     </form>
  </body>
</html>